package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.BusinessParam;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import com.tarena.lbs.business.pojo.vo.BusinessStoreVO;
import com.tarena.lbs.business.pojo.vo.BusinessVO;
import com.tarena.lbs.business.servcie.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理和商家相关的接口功能
 */
@Slf4j
@RestController
@Api(tags = "商家相关功能接口")
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    //商家的分页列表查询
    //读数据入参 单个属性 id name 对象数据 query结尾
    @ApiOperation(value = "查询商家列表")
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> pageList(BusinessQuery query)
            throws BusinessException {
        log.debug("查询商家列表:{}",query);
        // 调用businessService的pageList方法获取分页后的BusinessVO对象列表
        // query参数用于指定分页查询的条件，如页码、每页记录数等
        PageResult<BusinessVO> pageResult = businessService.pageList(query);

        return new Result<>(pageResult);
    }
    //表单填写完毕 新增提交商家数据保存
    //form请求表单格式参数 key=value&key=value
    //请求体携带json {"key","value"}
    //lbs智慧营销项目中 写操作 如果多个属性 命名类型Param后缀
    @ApiOperation(value = "新增商家")
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> save(@RequestBody BusinessParam param) throws BusinessException {
        log.debug("新增商家:{}",param);
        // 调用businessService的save方法，持久化参数param代表的数据
        businessService.save(param);
        return Result.success();//code=0 success=true
    }
    //商家的业务中 活动查询商家 和旗下店铺列表封装
    @ApiOperation(value = "商家详情")
    @GetMapping("/admin/basic/business/info/detail/{id}")
    public Result<BusinessStoreVO> busiStoreDetail(@PathVariable("id") Integer id)
        throws BusinessException {
        log.debug("商家详情:{}",id);
        // 根据商家ID获取商家店铺详情
        // businessId: 商家唯一标识，用于查询特定商家的店铺信息
        // 返回 BusinessStoreVO 对象，包含商家店铺的详细信息
        BusinessStoreVO businessStoreVO = businessService.busiStoreDetail(id);
        return new Result<>(businessStoreVO);
    }
    @ApiOperation(value = "审批商家")
    @PutMapping("/admin/basic/business/info/updateStatus")
    public Result<Void> updateStatus(@RequestBody BusinessParam param) throws BusinessException {
        log.debug("审批商家:{}",param);
//         调用businessService的updateStatus方法，更新商家状态
        businessService.updateStatus(param);
        return Result.success();
    }
}




















